package com.wjh.www.dao.mapper;

import com.wjh.www.annotation.mybatis.ReturnType;
import com.wjh.www.annotation.mybatis.Select;
import com.wjh.www.annotation.spring.Component;
import com.wjh.www.entity.po.Permission;
import com.wjh.www.proxy.constans.DataType;

import java.util.List;

/**
 * @author wjh
 * @date 2021/9/12 14:52
 * @Package com.wjh.anyview.dao.mapper
 */
@Component
public interface PermissionMapper {

    /**
     * 根据用户id查询他具有的权限
     *
     * @param userId 用户id
     * @return 返回List<Permission>
     */
    @Select(sql = "SELECT *\n" +
            "        FROM `permission`\n" +
            "        WHERE id IN (\n" +
            "            SELECT permission_id\n" +
            "            FROM `role_permission`\n" +
            "            WHERE role_id IN (\n" +
            "                SELECT role_id\n" +
            "                FROM `user_role`\n" +
            "                WHERE user_id = ?\n" +
            "            )\n" +
            "        )")
    @ReturnType(returns = DataType.LIST)
    List<Permission> listPermissionsByUserId(Long userId);
}
